package 蓝桥真题;

import java.util.Scanner;

public class 特别数的和 {
       static Scanner sc=new Scanner(System.in);
       static  int n;
       
       static boolean check(int x){
    	      while(x>0){
    	    	   int t=x%10;
    	    	   if(t==2||t==0||t==1||t==9)return true;
    	    	   t/=10;
    	      }
    	      return false;
       }
       public static void main(String[]args){
    	      int res=0;
    	      n=sc.nextInt();
    	      for(int i=1;i<=n;i++){
    	    	  if(check(i))res+=i;
    	      }
    	      System.out.print(res);
       }
}
